<?php

namespace Home\Model;

use Think\Model;

class PromotionModel extends Model {

    function get_promotion_price($goods_id,$spec_id) {
        if (!$goods_id || !$spec_id)
            return 0;

  
        $price = $old_price = M('GoodsSpec')->where('goods_id='.$goods_id.' AND spec_id='.$spec_id)->getField('price');


        $spec_price = $this->where("start_time<=" . time() . " AND end_time>=" . time() . " AND goods_id=" . $goods_id)->getField('spec_price');
        if (!empty($spec_price)) {
            $spec_price = unserialize($spec_price);

            if ($spec_price[$spec_id]['is_pro'] == 1) {
                if ($spec_price[$spec_id]['pro_type'] == 'price') {
                    $pro_price = round($old_price - $spec_price[$spec_id]['price'], 2);
                    if ($pro_price > 0) {
                        $price = $pro_price;
                    }
                }
                else
                    $price = round($old_price * $spec_price[$spec_id]['price'] / 1000, 4) * 100;
            }
        }
        return $price;
    }
    
    
    
    

}

?>
